package com.gyp.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

import java.util.ArrayList;
import java.util.List;

/**
 * @author xyb
 * @Description swagger相关配置
 * @since 20:20 2022/7/14
 */
@Configuration
@EnableSwagger2WebMvc
public class SwaggerConfig {



    @Bean
    public Docket createLoginDocker() {
        Docket docket=new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(getApiInfo())
                //分组名称
                .groupName("登录服务")
                .globalOperationParameters(getParameterList())
                .select()
                //这里指定Controller扫描包路径
                .apis(RequestHandlerSelectors.basePackage("com.gyp.controller.login"))
                .paths(PathSelectors.any())
                .build();
        return docket;
    }



    @Bean
    public Docket createUserDocker() {
        Docket docket=new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(getApiInfo())
                //分组名称
                .groupName("音频服务")
                .globalOperationParameters(getParameterList())
                .select()
                //这里指定Controller扫描包路径
                .apis(RequestHandlerSelectors.basePackage("com.gyp.controller.video"))
                .paths(PathSelectors.any())
                .build();
        return docket;
    }




    /**
     * 添加head参数配置
     */
    private List<Parameter> getParameterList() {
        ParameterBuilder clientIdTicket = new ParameterBuilder();
        List<Parameter> pars = new ArrayList<Parameter>();
        clientIdTicket.name("token").description("token令牌")
                .modelRef(new ModelRef("string"))
                .parameterType("header")
                .required(false).build(); //设置false，表示clientId参数 非必填,可传可不传！
        pars.add(clientIdTicket.build());
        pars.add(clientIdTicket.name("Accept-Language").description("国际化语言")
                .modelRef(new ModelRef("string"))
                .parameterType("header")
                .required(false).build());
        return pars;
    }


    public ApiInfo getApiInfo() {
        return new ApiInfoBuilder()
                .title("口型驱动系统API文档")
                .description("中影年年口型驱动系统")
                .version("1.0")
                .build();
    }

}
